package cn.hyh.controller;

import cn.hyh.service.ContextService;
import cn.hyh.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.lang.NonNull;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.HandlerMapping;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;

/**
 * @auther :hyh
 * @desc :
 * @date :2020/1/6
 */
@RestController
@RequestMapping("/hello")
public class HelloController {

	@Autowired
	private UserService userService;

	@Autowired
	private ContextService contextService;

	@RequestMapping("/test/{id}")
	public  String  SayHello(@PathVariable("id")Integer id,HttpServletRequest request){
		System.out.println(request.getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE));
		String name = userService.getName(id);
		return name + "  say：  你好";

	}
	@RequestMapping("/test")
	public  String  newString() {
		return contextService.getServletStr();
	}

	@RequestMapping("/testDate")
	public  String  dateTest(Date date, HttpServletRequest req){
		Object attribute = req.getAttribute(HandlerMapping.BEST_MATCHING_HANDLER_ATTRIBUTE);
		System.out.println(attribute);
		System.out.println(date);
		return date.getTime()+"";
	}
}
